import os
import re

from utils.logger import loger


def kill_process(port):
    ret = os.popen("netstat -nao|findstr " + str(port))
    str_list = ret.read()                         #.decode(charst='gbk')
    ret_list = re.split('', str_list)
    try:
        process_pid = list(ret_list[0].split())[-1]
        os.popen('taskkill /pid ' + str(process_pid) + ' /F')
        loger.info("" + str(port) + "端口已被释放")
    except:
        loger.info("" + str(port) + "端口未被使用")


if __name__ == '__main__':
    kill_process(6666)
